package org.openems.otdr;

import java.util.List;

import org.openems.meta.OtdrResultModelMeta;
import org.openems.model.OtdrResultModel;
import org.slim3.datastore.Datastore;
import org.slim3.datastore.ModelQuery;

public class OtdrTraceEntities {

    public OtdrSummaryEntities getOtdrTrace(String wavelength, String pulsewidth) {
        OtdrResultModelMeta e = OtdrResultModelMeta.get();
        
        ModelQuery<OtdrResultModel> modelQuery = Datastore.query(e);
        if (wavelength != null) {
            modelQuery = modelQuery.filter(e.wavelength.equal(Double.valueOf(wavelength)));
        }
        if (pulsewidth != null) {
            modelQuery = modelQuery.filter(e.pulseWidth.equal(Double.valueOf(pulsewidth)));
        }
        List<OtdrResultModel> results = modelQuery.asList();
        OtdrSummaryEntities ret = new OtdrSummaryEntities();
        for (OtdrResultModel model : results) {
            ret.entities.add( new OtdrSummaryEntity(Datastore.keyToString(model.getKey()), model.getWavelength(), model.getPulseWidth()) );
        }
        
        return ret;
    }

}
